package sxe.core.video;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import snobject.snImage;
import snobject.snObject;
import snobject.snObjectArgList;
import step.EvaluationFailure;
import step.FunctionWrapper;
import step.exceptions.ResourceUnavailableException;

public class stitchh extends FunctionWrapper {

	@Override
	public snObject Call(snObjectArgList argv) throws EvaluationFailure,
			ClassCastException, ArrayIndexOutOfBoundsException,
			ResourceUnavailableException {

		snImage snImage1 = argv.popImage();
		snImage snImage2 = argv.popImage();
		   
	   /* do not directly manipulate the original image, instead work with a copy */
	   BufferedImage buff1 = snImage1.getImageCopy();
	   BufferedImage buff2 = snImage2.getImageCopy();
		   
	   BufferedImage bTarget = new BufferedImage(buff1.getWidth(),
			   									 buff1.getHeight() + buff2.getHeight(),
			   									 buff1.getType());

	   // stitch the images together onto the target
	   Graphics2D g = bTarget.createGraphics();
	   g.drawImage(buff1, null, 0, 0);
	   g.drawImage(buff2, null, 0, buff1.getHeight());
	   
       return new snImage(bTarget);
	}

}
